package com.hkfrich.framework.web.interceptor;


import com.hkfrich.common.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author _HeiShuai
 * @Description //
 * @Date 17:44 2022/8/16
 * @Param
 * @return
 **/
@Component
public class RequestPrintInterceptor implements HandlerInterceptor {

    private final static Logger logger = LoggerFactory.getLogger(RequestPrintInterceptor.class);


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        logger.info("===============请求开始====================");
        logger.info("地址为：" + request.getLocalAddr());
        logger.info("请求方式为：" + request.getMethod());
        logger.info("请求全路径：" + request.getRequestURL().toString());
//        logger.info("请求参数"+ StringUtils.replaceBlank(HttpUtils.getBodyString(request)));
//        logger.info("请求参数"+ objectMapper.writeValueAsString(request.getParameterMap()));
        logger.info("请求时间为："+ DateUtils.getTime());
        logger.info("===============请求结束==================");
        return true;
    }


}